home *** CD-ROM | disk | FTP | other *** search
/ SuperHack / SuperHack CD.bin / Hack / UNIX / MULTLOGN.ZIP / MULTLOGN.C
C/C++ Source or Header  |  1996-06-23  |  4KB  |  182 lines

  1. /* Program   : To validate accounts & passwords on both
  2.                shadowed & unshadowed unix systems.
  3.    Author    : The Shining/UPi (UK Division)
  4.    Date      : Released 12/4/94
  5.    UNIX type : All unshadowed systems, and SUNOS shadowed systems */
  6.  
  7.  
  8. #include <stdio.h>
  9. #include <string.h>
  10. #include <pwd.h>
  11.  
  12.  
  13. FILE *fp;
  14.  
  15.  
  16. int pw_system( void ), shadowed( void ), unshadowed( void );
  17. void write_info( void ), display_notice( void );
  18.  
  19. struct passwd *pwentry, *getpwnam();
  20.  
  21. struct user {
  22.        char logname[10];
  23.        char key[9];
  24.        char salt[3];
  25. } u;
  26.  
  27.  
  28. char *getpass(), *pwdauth(), *crypt(), ans[2];
  29. int invalid_user, stat;
  30.  
  31.  
  32. int main( void )
  33. {
  34.  
  35.  strcpy(ans, "y");
  36.  
  37.  while (strcmp(ans, "y") == NULL)
  38.  {
  39.    invalid_user = stat = 0;
  40.     display_notice();
  41.      printf("Enter login id:");
  42.     scanf("%9s", u.logname);
  43.    strcpy(u.key, getpass("Password:"));
  44.  
  45.  
  46.  setpwent();
  47.  
  48.    if ((pwentry = getpwnam(u.logname)) == (struct passwd *) NULL)
  49.       invalid_user = 1;
  50.    else
  51.       strncpy(u.salt, pwentry->pw_passwd, 2);
  52.  
  53.  
  54.  if (invalid_user != 1) {
  55.  
  56.    if ((stat = pw_system()) == 1) {
  57.       if ((stat = unshadowed()) == NULL) {
  58.            printf("Unshadowed valid account! - storing details\n");
  59.           write_info();
  60.       }
  61.    }
  62.    else
  63.      if ((stat = shadowed()) == NULL) {
  64.           printf("SUNOS Shadowed valid account! - storing details\n");
  65.          write_info();
  66.      }
  67.      else
  68.         invalid_user = 2;
  69.  
  70.  }
  71.  
  72.  
  73.     if (invalid_user == 1)
  74.        printf("User unknown/not found in password file\n");
  75.  
  76.     if (invalid_user == 2 )
  77.        printf("Password invalid\n");
  78.  
  79.        printf("\n\nValidate another account?(y/n): ");
  80.        scanf("%1s", ans);
  81.  
  82.  endpwent();
  83.  }
  84. }
  85.  
  86.  
  87. /* Check to see if shadow password system is used, in SUNOS the field
  88.    in /etc/passwd starts with a '#', if not, check to see if entry
  89.    is 13 chars, if not shadow must be in use. */
  90.  
  91. int pw_system( void )
  92. {
  93.    if (strlen(pwentry->pw_passwd) != 13)
  94.       return(0);
  95.    else
  96.       if (strcmp(u.salt, "##") == NULL)
  97.          return(0);
  98.       else
  99.          return(1);
  100. }
  101.  
  102.  
  103. /* If system is unshadowed, get the 2 character salt from the password
  104.    file, and use this to encrypt the password entered. This is then
  105.    compared against the password file entry. */
  106.  
  107. int unshadowed( void )
  108. {
  109. if (pwentry->pw_passwd == crypt(u.key, u.salt))
  110.    return(0);
  111. else
  112.    return(1);
  113. }
  114.  
  115.  
  116. /* If SUNOS shadowe system is used, use the pwdauth() function to validate
  117.    the password stored in the /etc/security/passwd.adjunct file */
  118.  
  119. int shadowed( void )
  120. {
  121. int pwstat;
  122.  
  123. if (pwstat = pwdauth(u.logname, u.key) == NULL)
  124.    return(0);
  125. else
  126.    return(1);
  127. }
  128.  
  129.  
  130. /* Praise myself!!!! */
  131.  
  132. void display_notice( void )
  133. {
  134. system("clear");
  135.  printf("Unix Account login id & password validator.\n");
  136.  printf("For all unshadowed UNIX systems & shadowed SUNOS only.\n\n");
  137. printf("(c)1994 The Shining\n\n\n\n");
  138. }
  139.  
  140.  
  141. /* Open a file called 'data' and store account i.d. & password along with
  142.    other information retrieved from the password file */
  143.  
  144. void write_info( void )
  145. {
  146.  
  147. /* Open a file & store account information from pwfile in it */
  148.  
  149. if ((fp = fopen("data", "a")) == NULL) {
  150.      printf("error opening output file\n");
  151.     exit(0);
  152. }
  153.  
  154. fprintf(fp, "%s:%s:%d:", u.logname, u.key, pwentry->pw_uid);
  155.  fprintf(fp, "%d:%s:", pwentry->pw_gid, pwentry->pw_gecos);
  156.  fprintf(fp, "%s:%s\n", pwentry->pw_dir, pwentry->pw_shell);
  157. fclose(fp);
  158. }
  159.  
  160. -----cut here------------------------------------------------------------------
  161.  
  162.  
  163.  
  164. The above programs will not compile under non-ansi C compilers without quite
  165. a bit of modification. I have tested all these programs on SUNOS both
  166. shadowed & unshadowed, though they should work on other systems with
  167. little modification (except the shadow password cracker, which is SUNOS
  168. shadow system specific).
  169.  
  170.  
  171. Regards to the following guys :-
  172.  
  173.  
  174. Archbishop & The Lost Avenger/UPi, RamRaider/QTX,
  175. the guys at United International Perverts(yo Dirty Mac & Jasper!)
  176. and all I know.
  177.  
  178.  
  179. (c) 1994 The Shining (The NORTH!, U.K.)
  180.  
  181. *******************************************************************************
  182.